<template>
	<view class="flex flex-direction bg-white" >
		<scroll-view style="height: 100vh;" scroll-y>
		<homeFrontEnd :cur="PageCur" v-if="PageCur=='home'" ref="home"></homeFrontEnd>
		<learn-center  v-if="PageCur=='learnCenter'" ref="learnCenter"></learn-center>
		<mine  v-if="PageCur=='mine'" ref="mine"></mine>
		
		<view v-if="PageCur=='home'" :style="[{'margin-bottom': tabbarHeight + 'px'}]"></view>
		
		<!-- tabbar -->
		<view ref="tabbar" class="cu-bar tabbar  foot bg-white" style="z-index: 100;">
			<view :class="PageCur=='home'?'action text-blue':'action text-gray'" @click="NavChange" data-cur="home">
				<view class='cuIcon-home'></view>主页
			</view>
			<view v-if="develop" :class="PageCur=='learnCenter'?'action text-blue':'action text-gray'" @click="NavChange" data-cur="learnCenter">
				<view class='cuIcon-calendar'></view>学习中心
			</view>
			<view :class="PageCur=='mine'?'action text-blue':'action text-gray'" @click="NavChange" data-cur="mine">
				<view class='cuIcon-people'></view>个人
			</view>
		</view>
		</scroll-view>
	</view>
</template>

<script>
	import homeFrontEnd from './homeFrontEnd.vue'
	import mine from '../mine/mine.vue'
	import learnCenter from './learnCenter.vue'
	import mineApi from '../../api/mineApi.js'
	export default {
		components: {
			homeFrontEnd,
			mine,
			learnCenter
		},
		data() {
			return {
				PageCur: 'home',
				tabbarHeight: '',
			}
		},
		onLoad(){
			// console.log(this.develop)		
			this.PageCur=this.$Route.query.page?this.$Route.query.page:'home';
		},
		onShow() {
			//重新获取数据刷新阅读量
			if(this.PageCur=='home'){
				this.$nextTick(()=>{
					this.$refs.home.getData()
				})
			} else if(this.PageCur == 'mine') {
				mineApi.getMemberInfo(this.$store.getters.userid).then(res=>{
					if (res.data) {
						this.$nextTick(()=>{
							this.$refs.mine.user = res.data;
						})
					}
				}).catch(err => {
					console.log(err);
				});
			}
			
		},
		mounted() {
			let page = this.$Route.query.page;
			if(!page || page == '') {
				page = 'home'
			}
			this.PageCur=page;
			if(this.$refs.tabbar.$el){
				this.tabbarHeight = this.$refs.tabbar.$el.offsetHeight;
			}
		},
		methods: {
			NavChange: function(e) {
				this.PageCur = e.currentTarget.dataset.cur
				if(this.PageCur=="mine" && !uni.getStorageSync('Access-Token')){
					this.$verifyLogin().then(()=>{
						this.$Router.push({name:'loginFrontEnd'})
					}).catch(()=>{
						this.PageCur='home'
					})
				}
			}
		}
	}
</script>

<style>

</style>
